package cn.dlc.com.service;

import cn.dlc.com.controller.JsdwController;
import cn.dlc.com.entity.Jsdw;
import cn.dlc.com.mapper.JsdwMapper;
import cn.dlc.com.util.PostUtils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.databind.util.JSONPObject;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

/**
 * @Author: dlc
 * @Date: 2022/4/26 - 13:20
 */
@Service
public class JsdwServiceImpl extends ServiceImpl<JsdwMapper, Jsdw> implements IJsdwService {

    @Autowired
    private JsdwMapper jsdwMapper;

    public void set(String url, String params){


        try {

            HttpEntity entity = PostUtils.createRequestPost(url, params);

            String result= EntityUtils.toString(entity);
            JSONObject jsonObject = JSONObject.parseObject(result);

            JSONObject data = jsonObject.getJSONObject("data");

            JSONArray resultlist = data.getJSONArray("resultlist");

            List<Jsdw> jsdwList = resultlist.toJavaList(Jsdw.class);

            this.saveBatch(jsdwList);

            System.out.println("end");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
